var loginName = document.getElementById("userName");
var loginPwd = document.getElementById("passWord");
var access_token = "";
var tuichu = "再按一次退出程序";
var backButtonPress = 0;

(function(e) {

	mui.init({
		keyEventBind: {
			backbutton: true //开启back按键监听
		}
	});

	mui.plusReady(function() {
		plus.navigator.setStatusBarBackground('#3085D0');
		clearAllWindows();

		mui.back = function(event) {
			backButtonPress++;
			if(backButtonPress > 1) {
				plus.runtime.quit();
			} else {
				plus.nativeUI.toast(tuichu);
			}
			setTimeout(function() {
				backButtonPress = 0;
			}, 1000);
			return false;
		};

	});

})(mui);

$("#loginBtn").click(function() {
	getToken();
});

//登录
function getToken() {
	var username = loginName.value.trim();
	var passWord = loginPwd.value.trim();
	//测试用
//	username = 'admin';
//	passWord = '123456';

	var jsonData = {
		op: "Phone_Login",
		Login: username,
		PassWord: passWord
	}

	if(checkParams(jsonData)) {
		mui.toast("请求失败,请稍后再试");
		return;
	}

	var opts = {
		url: "",
		addressUrl: "testline",
		requestType: "POST",
		pastDate: jsonData
	};

	console.log(JSON.stringify(opts));

	plus.nativeUI.showWaiting();
	crossDomainAjax(opts, function(data) {
		plus.nativeUI.closeWaiting();
		console.log(JSON.stringify(data));
		localStorage.setItem("user_info" , JSON.stringify(data));
		var postData = {
			pageflag: "login.tml"
		}
		var pageChange1 = {
			pageUrl: "index.html",
			createNew: true,
			postData: postData,
			aniShow: "fade-in"
		}
		pageChange(pageChange1);
	});
}